//
//  BookTabBarController.swift
//  book
//
//  Created by 孙磊 on 2019/3/17.
//  Copyright © 2019 sunlei. All rights reserved.
//

import UIKit

class BookTabBarController: UITabBarController {

    override func viewDidLoad()
    {
        super.viewDidLoad();
        UITabBar.appearance().backgroundColor = UIColor.white
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1.0), NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12)], for: .normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor(red: 232/255, green: 92/255, blue: 66/255, alpha: 1.0), NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12)], for: .selected)
        let vc1 = addTabBarChildViewController(childVC: SelfViewController(), title: "书架", imageName: "tabitem_self", selectedImageName: "tabitem_self_select", tag: 0)
        let vc2 = addTabBarChildViewController(childVC: StoreViewController(), title: "书城", imageName: "tabitem_store", selectedImageName: "tabitem_store_select", tag: 1)
        let vc3 = addTabBarChildViewController(childVC: MyViewController(), title: "我的", imageName: "tabitem_my", selectedImageName: "tabitem_my_select", tag: 2)
        self.viewControllers = [vc1,vc2,vc3]
        
    }
    
    private func addTabBarChildViewController(childVC: UIViewController, title: String, imageName: String, selectedImageName: String, tag: Int)-> UINavigationController
    {
        let vcItem = UITabBarItem(title: title, image: UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal), selectedImage: UIImage(named: selectedImageName)?.withRenderingMode(.alwaysOriginal));
        vcItem.tag = tag;
        childVC.tabBarItem = vcItem;
        
        let navigationVC = UINavigationController(rootViewController: childVC);
        return navigationVC
    }
    
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
    {
        print("didSelectIndex:\(item.tag)");
    }

}
